import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const routes = [
    {
        path: '/',
        name: 'Index',
        component: () => import('@/views/index'),
        meta: {
            title: '云发单',
            keepAlive: true
        }
    }, {
        path: '/Group',
        name: 'Group',
        component: () => import('@/views/joinGroup'),
        meta: {
            title: '入群欢迎',
            keepAlive: false
        }
    }
    , {
        path: '/Pay',
        name: 'Pay',
        component: () => import('@/views/pay'),
        meta: {
            title: '开通发单助手',
            keepAlive: false
        }
    }
    , {
        path: '/Rules',
        name: 'Rules',
        component: () => import('@/views/rules'),
        meta: {
            title: '使用指南',
            keepAlive: false
        }
    }
    , {
        path: '/CollectManage',
        name: 'CollectManage',
        component: () => import('@/views/collectManage'),
        meta: {
            title: '采集群管理',
            keepAlive: false
        }
    }
    , {
        path: '/followFriends',
        name: 'followFriends',
        component: () => import('@/views/followFriends'),
        meta: {
            title: '朋友圈发单',
            keepAlive: false
        }
    }, {
        path: '/friendsDetail',
        name: 'friendsDetail',
        component: () => import('@/views/friendsDetail'),
        meta: {
            title: '朋友圈预览',
            keepAlive: false
        }
    }, {
        path: '/exchangeRecord',
        name: 'exchangeRecord',
        component: () => import('@/views/exchangeRecord'),
        meta: {
            title: '兑换记录',
            keepAlive: false
        }
    }, {
        path: '/groupList',
        name: 'groupList',
        component: () => import('@/views/groupList'),
        meta: {
            title: '群列表',
            keepAlive: false
        }
    }, {
        path: '/keywordList',
        name: 'keywordList',
        component: () => import('@/views/keywordList'),
        meta: {
            title: '关键词回复',
            keepAlive: false
        }
    }, {
        path: '/keywordPreview',
        name: 'keywordPreview',
        component: () => import('@/views/keywordPreview'),
        meta: {
            title: '关键词管理',
            keepAlive: false
        }
    }, {
        path: '/personalGuide',
        name: 'personalGuide',
        component: () => import('@/views/personalGuide'),
        meta: {
            title: '个人号导购',
            keepAlive: false
        }
    }, {
        path: '/followGroup',
        name: 'followGroup',
        component: () => import('@/views/followGroup'),
        meta: {
            title: '智选跟群',
            keepAlive: false
        }
    },
    {
        path: '/dataCompass',
        name: 'dataCompass',
        component: () => import('@/views/dataCompass'),
        meta: {
            title: '数据报表',
            keepAlive: false
        }
    },
    {
        path: '/addAutoFollow',
        name: 'AddAutoFollow',
        component: () => import('@/views/addAutoFollow'),
        meta: {
            title: '智选跟群',
            keepAlive: false
        }
    },
    {
        path: '/customRule',
        name: 'CustomRule',
        component: () => import('@/views/customRule'),
        meta: {
            title: '自定义跟群教程',
            keepAlive: false
        }
    }
    
]

routes.forEach(route => {
    route.path = route.path || '/' + (route.name || '')
})

const router = new Router({
    routes
})

router.beforeEach((to, from, next) => {
    const title = to.meta && to.meta.title
    if (title) {
        document.title = title
    }
    next()
})

export {
    router
}
